package info.yaohua.servlet;

import info.yaohua.dao.Ac02Dao;
import info.yaohua.dto.Ac02Dto;
import info.yaohua.util.SessionNull;

import java.io.IOException;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class EditPostServlet
 */
@WebServlet("/EditPostServlet")
public class EditPostServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EditPostServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		if (session == null || session.getAttribute("ac01")==null) {
			SessionNull.forwordTo(request, response);
		} else {
			String id = request.getParameter("id");
			Ac02Dao ac02Dao = new Ac02Dao();
			Ac02Dto ac02Dto =new Ac02Dto();
			ac02Dto.setId(Integer.parseInt(id));
			try {
				ac02Dto = ac02Dao.findAc02ById(ac02Dto);
				request.setAttribute("sac001", ac02Dto.getSac001());
				request.setAttribute("sac002", ac02Dto.getSac002());
				request.setAttribute("sac003", ac02Dto.getSac003());
				request.setAttribute("id", ac02Dto.getId());
				request.setAttribute("sac006", ac02Dto.getSac006());
				request.setAttribute("sac007", ac02Dto.getSac007());
				request.setAttribute("sac008", ac02Dto.getSac008());
				RequestDispatcher view1 = request.getRequestDispatcher("/post.jsp");
				view1.forward(request, response);
			} catch (NamingException | SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
			
		}
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
